﻿using Microsoft.Extensions.DependencyInjection;
using Quartz;
using System.Threading.Tasks;
using Zocono.WCS.HangfireHost.TaskJobs;

namespace Zocono.WCS.HangfireHost.QuartzJobs
{
    public class QuartzRepeatReadDbJob : IJob
    {
        private readonly IServiceScopeFactory _serviceScopeFactory;

        public QuartzRepeatReadDbJob(IServiceScopeFactory serviceScopeFactory)
        {
            this._serviceScopeFactory = serviceScopeFactory;
        }

        public async Task Execute(IJobExecutionContext context)
        {
            var jobDataMap = context.JobDetail.JobDataMap;
            string programeCode = jobDataMap.GetString("programeCode");
            string jobName = jobDataMap.GetString("jobName");
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var _RepeatReadDbJob = scope.ServiceProvider.GetRequiredService<RepeatReadDbJob>();
                await _RepeatReadDbJob.DoJob(programeCode, jobName);
            }
        }
    }
}
